/* eslint-disable import/order */
/* eslint-disable import/no-duplicates */
import { APP_INITIALIZER, DEFAULT_CURRENCY_CODE, NgModule, Type } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SimpleInterceptor } from '@delon/auth';
import zh from '@angular/common/locales/zh';
registerLocaleData(zh);
// #region global third module

const GLOBAL_THIRD_MODULES: Array<Type<any>> = [];

// #endregion

// #region Http Interceptors
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

import { BusinessInterceptor, DefaultInterceptor } from '@core';

const INTERCEPTOR_PROVIDES = [
  { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true },
  { provide: HTTP_INTERCEPTORS, useClass: BusinessInterceptor, multi: true },
  { provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true }
];
// #endregion

// #region Startup Service
import { StartupService } from '@core';
export function StartupServiceFactory(startupService: StartupService): () => Promise<void> {
  return () => startupService.load();
}
const APPINIT_PROVIDES = [
  StartupService,
  {
    provide: APP_INITIALIZER,
    useFactory: StartupServiceFactory,
    deps: [StartupService],
    multi: true
  },
  { provide: DEFAULT_CURRENCY_CODE, useValue: '￥' },
  { provide: RouteReuseStrategy, useClass: ReuseTabStrategy, deps: [ReuseTabService] }
];
// #endregion

import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { RoutesModule } from './routes/routes.module';
import { registerLocaleData } from '@angular/common';
import { RouteReuseStrategy, RouterModule } from '@angular/router';
import { ReuseTabService, ReuseTabStrategy } from '@delon/abc/reuse-tab';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, BrowserAnimationsModule, HttpClientModule, CoreModule, RoutesModule, RouterModule, ...GLOBAL_THIRD_MODULES],
  providers: [...INTERCEPTOR_PROVIDES, ...APPINIT_PROVIDES],
  bootstrap: [AppComponent]
})
export class AppModule {}
